<%@page import="com.hp.ccue.identity.util.WebRequestContextUtils"%>
<%@page
	import="com.hp.ccue.identity.authentication.domain.token.AccessTokenResponse"%>
<%@page
	import="com.hp.ccue.identity.authentication.domain.token.AccessTokenRequest"%>
<%@page import="com.hp.ccue.identity.IdmClient"%>
<%@page import="com.hp.ccue.identity.common.IdmConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>User Details</title>
<style type="text/css">
body {
	width: 80%;
	height: 80%;
	position: absolute;
	margin-left: 50px;
	margin-top: 40px;
}

#contentDetail {
	width: 80%;
	height: 50%;
}
</style>
<script type="text/javascript">
	contentDetail
	function viewUsers() {
		var tenant = document.getElementById('tenant').value;
		window.frames["contentDetail"].src = "showUser.jsp?tenant=" + tenant;
	}
	function viewGroups() {
		var tenant = document.getElementById('tenant').value;
		window.frames["contentDetail"].src = "showGroup.jsp?tenant=" + tenant;
	}
	function viewRoles() {
		var tenant = document.getElementById('tenant').value;
		window.frames["contentDetail"].src = "showRole.jsp?tenant=" + tenant;
	}
</script>
</head>
<body>

	<%
	    if (null != session.getAttribute(IdmConstant.IDM_X_AUTH_TOKEN)) {
	        out.println("<h1>This is a secure page. Should be authenticated by IdM.</h1>");
	    }
	    Enumeration<String> e = session.getAttributeNames();
	    while (e.hasMoreElements()) {
	        String sessionAttrName = e.nextElement();
	        out.print("<span style=\"color:red padding-left: 5em;font-weight:bold;\">");
	        out.print(sessionAttrName);
	        out.print(": </span><span>");
	        Object sessionAttrValue = session.getAttribute(sessionAttrName);
	        if (sessionAttrValue instanceof AccessTokenResponse) {
	            out.print(sessionAttrValue);
	        } else {
	            out.print(sessionAttrValue);
	        }

	        out.print("</span><br>");
	    }
	%>
	<h2>
		WebAppName:
		<%
	    if (request.getContextPath().length() == 0) {
	        out.println("/");
	    } else {
	        out.println(request.getContextPath().substring(1));
	    }
	%>
	</h2>
	/<%=WebRequestContextUtils.getIdmClient()%><br>
	<a href="../index.jsp">Return</a>
	<%
	    if (WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser() != null) {
	%>
	<br>
	<h3>View Users</h3>
	<table>
		<tr>
			<td>User:</td>
			<td colspan="2"><%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser().getName()%>/=///<%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentUser().getMetadata()%></td>
		</tr>
		<tr>
			<td>Tenant:</td>
			<td colspan="2"><input id="tenant" type=text
				value="<%=WebRequestContextUtils.getIdmClient().getAuthenticationService().getCurrentTenant().getName()%>"></td>
		</tr>
		<tr>
			<td><input type="button" onclick="viewUsers()" value="viewUsers"></td>
			<td><input type="button" onclick="viewGroups()" value=viewGroups></td>
			<td><input type="button" onclick="viewRoles()" value=viewRoles></td>
		</tr>
	</table>
	<%
	    }
	%>
	<iframe id="contentDetail" src="loginResponse.jsp"></iframe>

</body>
</html>